<template>
	<view class="msg-dialog">
		<uni-popup ref="popup" :mask-click="false" background-color="#fff" @change="onPopVisibleChange">
			<view class="popup" type="center">
				<view class="popup-header flex-between">
					<view class="popup-header-left">
						{{options.title}}
					</view>
					<view class="popup-header-right">
						<uni-icons
							type="closeempty" 
							color="#fff" 
							size="20"
							@click="onClose">
						</uni-icons>
					</view>
				</view>
				<view class="popup-content">
					<slot>{{options.message}}</slot>
				</view>
				<view class="popup-footer">
					<view class="btn cancel-btn" @click="onClose">取消</view>
					<view class="btn confirm-btn" @click="onConfirm">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShowPop: true,
				options: {
					title: '提示',
					message: '',
					confirm: () => {}
				}
				
			};
		},
		methods: {
			open(options = {}) {
				this.options = {
					...this.options,
					...options
				}
				this.$refs.popup.open('center');
			},
			onPopVisibleChange ({show}) {
				this.isShowPop = show;
			},
			onClose() {
				this.$refs.popup.close();
			},
			onConfirm() {
				if (typeof this.options.confirm === 'function') {
					this.options.confirm();
				}
				this.onClose();
			}
		}
	}
</script>

<style lang="scss">
	.popup {
		width: 80vw;
		height: 20vh;
		display: flex;
		flex-direction: column;
			
		&-header {
			padding: 9px 10px;
			color: #fff;
			background-color: $uni-color-primary;
			
			&-left {
				font-size: 17px;
			}
			
			&-right {
				font-size: 15px;
			}
		}
		
		&-content {
			padding: 25px;
			flex: 1;
			color: #333;
		}
		
		&-footer {
			display: flex;
			align-items: center;
			width: 100%;
			
			.btn {
				width: 50%;
				padding: 8px 0;
				font-size: 17px;
				text-align: center;
			}
			
			.cancel-btn {
				color: #999;
				background-color: #fff;
				border-top: 1px solid #ccc;
			}
			
			.confirm-btn {
				color: #fff;
				background-color: #0BB78E;
				border-top: 1px solid #0BB78E;
			}
		}
	}
</style>